﻿//作业3
namespace ConsoleApp2._0923;

public partial class Demo
{
    public static void Test()
    {
        Console.WriteLine("一千以内的水仙花数有：");
        for (int i = 1; i < 1000; i++)
        {
            if (IsNumber(i))
            {
                Console.WriteLine(i);
            }
        } 
        // 判断一个数是否是水仙花数
        static bool IsNumber(int number)
        {
            int originalNumber = number;
            int sum = 0;
            int digits = number.ToString().Length; 
            while (number > 0)
            {
                int digit = number % 10; 
                sum += (int)Math.Pow(digit, digits); 
                number /= 10; 
            }
            return sum == originalNumber; 
        }
    }
}